import request from '@/axios'
import { DepartmentItem, DepartmentUserParams, DepartmentUserResponse, UserResponse } from './types'

export const getDepartmentApi = (data: object = {}) => {
  return request.post<DepartmentItem[]>({ url: '/api/dept/tree', data })
}

// 用户接口
export const userDeptPageApi = (data: object = {}) => {
  return request.postPage<UserResponse>({ url: '/api/user/dept/page', data })
}

// 新增用户
export const saveUserApi = (data: object = {}) => {
  return request.post<UserResponse[]>({ url: '/api/user', data })
}

// 修改用户
export const updateUserApi = (data: object = {}) => {
  return request.put<UserResponse[]>({ url: '/api/user', data })
}

export const saveDeptApi = (data: object = {}) => {
  return request.post<DepartmentItem[]>({ url: '/api/dept', data })
}

export const updateDeptApi = (data: object = {}) => {
  return request.put<DepartmentItem[]>({ url: '/api/dept', data })
}

export const deleteDeptApi = (data: object = {}) => {
  return request.delete<DepartmentItem[]>({ url: '/api/dept', data })
}

export const getUserByIdApi = (params: DepartmentUserParams) => {
  return request.get<DepartmentUserResponse>({ url: '/mock/department/users', params })
}

export const deleteUserByIdApi = (ids: string[] | number[]) => {
  return request.post({ url: '/mock/department/user/delete', data: { ids } })
}

export const saveDepartmentApi = (data: any) => {
  return request.post({ url: '/mock/department/save', data })
}

export const deleteDepartmentApi = (ids: string[] | number[]) => {
  return request.post({ url: '/mock/department/delete', data: { ids } })
}

export const getDepartmentTableApi = (params: any) => {
  return request.get({ url: '/mock/department/table/list', params })
}
